home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 6 code / TCP / NewsWatcher / NW Source / Source / child.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-05  |  3.6 KB  |  136 lines  |  [TEXT/MMCC]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     child.c
  4.  
  5.     This module manages the parent/child window relationship
  6.     
  7.     Copyright © 1994-1995, Northwestern University.
  8.  
  9. ----------------------------------------------------------------------------*/
  10.  
  11. #include "glob.h"
  12. #include "child.h"
  13. #include "memutil.h"
  14.  
  15.  
  16.  
  17. /*----------------------------------------------------------------------------
  18.     AddChild 
  19.     
  20.     Add a child window to the child window list of a parent window.
  21.             
  22.     Entry:    parent = pointer to parent window.
  23.             child = pointer to child window.
  24.             
  25.     Exit:    function result = error code.
  26. ----------------------------------------------------------------------------*/
  27.  
  28. OSErr AddChild (WindowPtr parent, WindowPtr child)
  29. {
  30.     TWindow **parentInfo;
  31.     TChild **newChild;
  32.     OSErr err = noErr;
  33.     
  34.     parentInfo = (TWindow**) GetWRefCon(parent);
  35.     
  36.     err = MyNewHandle(sizeof(TChild), &newChild);
  37.     if (err != noErr) return err;
  38.     (**newChild).childWindow = child;
  39.     (**newChild).next = (**parentInfo).childList;
  40.     (**parentInfo).childList = newChild;
  41.     return noErr;
  42. }
  43.  
  44.  
  45.  
  46. /*----------------------------------------------------------------------------
  47.     RemoveChild 
  48.     
  49.     Remove a child window from the child window list of a parent window.
  50.             
  51.     Entry:    parent = pointer to parent window.
  52.             child = pointer to child window.
  53. ----------------------------------------------------------------------------*/
  54.  
  55. void RemoveChild (WindowPtr parent, WindowPtr child)
  56. {
  57.     TWindow **parentInfo;
  58.     TChild **current, **prev;
  59.     
  60.     if (parent == nil) return;
  61.     parentInfo = (TWindow**) GetWRefCon(parent);
  62.     for (current = prev = (**parentInfo).childList;
  63.         current != nil && (**current).childWindow != child;
  64.         prev = current, current = (**current).next) /* do nothing */;
  65.     if (current != nil) {
  66.         if (prev == current) {
  67.             (**parentInfo).childList = (**current).next;
  68.         } else {
  69.             (**prev).next = (**current).next;
  70.         }
  71.         MyDisposeHandle(current);
  72.     }
  73. }
  74.  
  75.  
  76.  
  77. /*----------------------------------------------------------------------------
  78.     FindChildByIndex 
  79.     
  80.     Locate a child window from an index in a group or subject array.
  81.             
  82.     Entry:    wind = pointer to group or subject window.
  83.             index = index in group or subject array.
  84.             
  85.     Exit:    function result = pointer to child window, or nil if none.
  86. ----------------------------------------------------------------------------*/
  87.     
  88. WindowPtr FindChildByIndex (WindowPtr wind, short index)
  89. {
  90.     TWindow **info, **childInfo;
  91.     TChild **childListRec;
  92.     WindowPtr child;
  93.     TWindowKind kind;
  94.     
  95.     info = (TWindow**)GetWRefCon(wind);
  96.     kind = (**info).kind;
  97.     for (childListRec = (**info).childList; childListRec != nil; 
  98.         childListRec = (**childListRec).next) 
  99.     {
  100.         child = (**childListRec).childWindow;
  101.         childInfo = (TWindow**)GetWRefCon(child);
  102.         if (kind == kSubject) {
  103.             if ((**childInfo).parentSubject == index) return child;
  104.         } else {
  105.             if ((**childInfo).parentGroup == index) return child;
  106.         }
  107.     }
  108.     return nil;
  109. }
  110.  
  111.  
  112.  
  113. /*----------------------------------------------------------------------------
  114.     FindChild 
  115.     
  116.     Locate a child window from a cell in a group or subject window list.
  117.             
  118.     Entry:    wind = pointer to group or subject window.
  119.             theCell = the cell in the window list.
  120.             
  121.     Exit:    function result = pointer to child window, or nil if none.
  122. ----------------------------------------------------------------------------*/
  123.     
  124. WindowPtr FindChild (WindowPtr wind, Cell theCell)
  125. {
  126.     TWindow **info;
  127.     ListHandle theList;
  128.     short index, cellDataLen;
  129.     
  130.     info = (TWindow**)GetWRefCon(wind);
  131.     theList = (**info).theList;
  132.     cellDataLen = 2;
  133.     LGetCell(&index, &cellDataLen, theCell, theList);
  134.     return FindChildByIndex(wind, index);
  135. }
  136.